package pl.cat;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.StreamCorruptedException;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;

public class DataClient {
	
	private static final String TAG = "DataClient";
	private static final String JUG_FILE = "jugFile";

	
	private Context context;
	
	public DataClient(Context c) {
		context = c;
	}
	
	public synchronized List<JugEvent> readFile(String loc){
		File file = new File(context.getFilesDir(), loc);
		FileInputStream fis;
		List<JugEvent> events = new ArrayList<JugEvent>();
		try {
			fis = new FileInputStream(file);
			ObjectInputStream ois = new ObjectInputStream(fis);
			
			events = (List<JugEvent>) ois.readObject();
			
			Log.d(TAG, "CZYTANA LISTA: ");
			Log.d(TAG, events.toString());
			Log.d(TAG, events.size()+"");
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (StreamCorruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return events;
	}

}
